package com.efeichong.project.domain.entity.db;

import com.efeichong.audit.InsertDefault;
import com.efeichong.audit.UpdateDefault;
import com.efeichong.common.config.AuditorHolder;
import com.efeichong.common.domain.BaseEntity;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

import javax.persistence.*;


/**
 * @author
 * @date 2020/11/25
 * @description 数据字典详细
 */
@Setter
@Getter
@Entity
@Table(indexes = {
        @Index(name = "PRIMARY", columnList = "id", unique = true),
        @Index(name = "fk_dict_id", columnList = "dict_id"),
})
@DynamicInsert
@DynamicUpdate
public class SysDictDetail extends BaseEntity {
    /**
     * 字典
     */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "[dict_id]")
    private SysDict dict;

    /**
     * 字典标签
     */
    @Column(name = "[label]", columnDefinition = "varchar(100) comment'字典标签'")
    private String label;

    /**
     * 字典键值
     */
    @Column(name = "[value]", columnDefinition = "int comment'字典键值'")
    private Integer value;

    /**
     * 字典类型
     */
    @Column(name = "[type]", columnDefinition = "varchar(100) comment'字典类型'")
    private String type;

    /**
     * 字典排序
     */
    @Column(name = "[sort]", columnDefinition = "int comment'字典排序'")
    private Integer sort;

    /**
     * 是否默认（1是 0否）
     */
    @Column(name = "[is_default]", columnDefinition = "int default'0' comment'是否默认（1是 0否）'")
    private Integer isDefault;

    /**
     * 备注
     */
    @Column(name = "[remark]", columnDefinition = "varchar(500) comment'备注'")
    private String remark;

    /**
     * 创建者
     */
    @InsertDefault(val = AuditorHolder.class)
    @JoinColumn(name = "[create_by]")
    @ManyToOne(fetch = FetchType.LAZY)
    private SysUser createBy;

    /**
     * 更新者
     */
    @UpdateDefault(val = AuditorHolder.class)
    @JoinColumn(name = "[update_by]")
    @ManyToOne(fetch = FetchType.LAZY)
    private SysUser updateBy;
}
